﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <#include "../common/header.ftl">
    <script src="/js/plugins/jquery-bootstrap/jquery.bootstrap.min.js"></script>
    <script>
        $(function () {
            //删除单条数据
            $(".btn-delete").click(function () {
                var url = $(this).data("url");
                $.messager.confirm("提示","确定要删除这条数据吗？",function () {
                    $.get(url,function (data) {
                        if(data.success){
                           msg("删除成功");
                        }else {
                            $.messager.alert(data.msg);
                        }
                    });
                })
            });

            //注意着条语句用来处理数组的中括号问题的，不然会导致后台接收数组为空；
            $.ajaxSettings.traditional=true;
            
            //  批量删除，点击按钮全选
            $(".allData").click(function () {
                $(".someData").prop("checked",this.checked);
            });

            //处理全选按钮合理问题
            $(".someData").click(function () {
                if($(".someData:checked").size()==$(".someData").size()){
                    $(".allData").prop("checked",true);
                }else {
                    $(".allData").prop("checked",false);
                }
            });
            
            $("#btn_bathDelete").click(function () {
                var ids=[];
                $.each($(".someData:checked"),function (i,ele) {
                    ids[i]=$(ele).data("id");
                })
                if(ids.length==0){
                    $.messager.alert("提示：","请选择要删除的数据");
                    return;
                }

                $.messager.confirm("重要提示：","确定要删除这些数据吗",function () {
                    $.post("/employee/batchdelete.do",{ids:ids},function (data) {
                        if(data.success){
                            msg("删除成功");
                        }else {
                            $.messager.alert(data.msg);
                        }
                    })
                })
            });


            //  导入数据的模态框
            $(".btn-import").click(function () {
                $("#importModal").modal();
            });

            //提交表单
            $(".btn-submit").click(function () {
                $("#editForm").submit();
            });

        })

    </script>

</head>
<body>

<div class="container-fluid" style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-2">
            <#assign menu="employee">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-10">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">员工管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <input type="hidden" name="pageSize" id="pageSize" value="20">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入姓名/电话">
                </div>
                <div class="form-group">
                    <label>部门:</label>
                    <select class="form-control" name="deptId">
                        <option value="-1">全部</option>
                        <#list (depts)! as d>
                            <option value="${(d.id)!}">${(d.name)!}</option>
                        </#list>
                    </select>
                    <script>
                        // 回显查询的部门
                        $(function () {
                            $("[name='deptId']").val(${(qo.deptId)!});
                        });

                    </script>
                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a href="/employee/input.do" class="btn btn-success">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>

                <a href="/employee/export.do" class="btn btn-success">
                    <span class="glyphicon glyphicon-export"></span> 导出
                </a>
                <a class="btn btn-success btn-import">
                    <span class="glyphicon glyphicon-import"></span> 导入
                </a>

                <a id="btn_bathDelete" class="btn btn-danger">
                    <span class="glyphicon glyphicon-trash"></span>批量删除
                </a>

            </form>
            <table class="table table-striped table-hover" >
                <tr>
                    <th><input type="checkbox" class="allData"></th>
                    <th>编号</th>
                    <th>名称</th>
                    <th>性别</th>
                    <th>电话</th>
                    <th>年龄</th>
                    <th>部门</th>
                    <th>操作</th>
                </tr>
                <#list ro.list as emp>
                    <tr>
                        <td><input type="checkbox" class="someData" data-id="${(emp.id)!}"></td>
                        <td>${(emp_index+1)!}</td>
                        <td>${(emp.name)!}</td>
                        <td>${(emp.genderName)!}</td>
                        <td>${(emp.phone)!}</td>
                        <td>${(emp.age)!}</td>
                        <td>${(emp.dept.name)!}</td>
                        <td>
                            <a class="btn btn-info btn-xs" href="/employee/input.do?id=${(emp.id)!}">
                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                            </a>
                            <a class="btn btn-danger btn-xs btn-delete" data-url="/employee/delete.do?id=${(emp.id)!}">
                                <span class="glyphicon glyphicon-trash"></span> 删除
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>


<!-- 导入员工信息Modal -->
<div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">批量导入员工数据</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/employee/import.do" method="post" id="editForm" enctype="multipart/form-data">
                    <div class="form-group" >
                        <label class="col-lg-3 control-label">导入的文件：</label>
                        <div class="col-lg-6">
                            <input type="file" class="form-control" name="xls">
                        </div>
                    </div>

                    <a href="/template/employee.xls" class="btn btn-success text-center">
                        <span class="glyphicon glyphicon-download"></span> 下载excel导入模板
                    </a>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary btn-submit">提交</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>